package acm.蓝桥1;

import java.util.Scanner;

public class F {
    static int n;
    static int k;
    static int t;

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        n = sc.nextInt();
        k = sc.nextInt();
        t = sc.nextInt();

        long res=0;
        for (long i = 0; i < t; i++) {
            long j = i * n%k;
            long sn=1 +(j+1)*j/2%k;
            res+=sn%k;
        }
        System.out.println(res);
    }
}
